package cn.easier.activity.console.repository;

import cn.easier.activity.web.entity.ActivityPrize;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 活动奖品 Repository
 */
@Repository
public interface ActivityPrizeRepository extends JpaRepository<ActivityPrize, Integer> {

    /**
     * 获取某活动奖品列表
     *
     * @param activityInfoId 活动编号
     * @return
     */
    List<ActivityPrize> findActivityPrizesByActivityInfoIdAndStatus(Integer activityInfoId, Integer status);

    /**
     * 获取某活动指定奖品
     *
     * @param id 奖品编号
     * @param activityInfoId 活动编号
     * @return
     */
    ActivityPrize findActivityPrizeByIdAndActivityInfoId(Integer id, Integer activityInfoId);

    /**
     * 删除某活动指定奖品
     *
     * @param id 奖品编号
     * @param activityInfoId 活动编号
     * @return 影响行数
     */
    @Query(value = "DELETE FROM `activity_prize` WHERE id = ? AND activity_info_id = ?", nativeQuery = true)
    @Modifying
    int deleteFlag(Integer id,Integer activityInfoId);

    List<ActivityPrize> findAllByActivityInfoId(Integer activityInfoId);

    ActivityPrize findByActivityInfoIdAndPrizeClawType(Integer activityInfoId, String prizeClawType);

    ActivityPrize findByPrizeClawTypeAndStatus(String prizeClawType, Integer status);

}
